﻿using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace FM.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            var filePath = "d:/db/Exhibition.zip";
            var json = UploadFile(filePath).GetAwaiter().GetResult();
            Console.WriteLine(json);
        }

        static async Task<string> UploadFile(string filePath)
        {
            HttpClient httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Add("accesstoken", "abcd");
            httpClient.DefaultRequestHeaders.Add("app", "test");
            httpClient.DefaultRequestHeaders.Add("chunkNumber", "1");
            httpClient.DefaultRequestHeaders.Add("identifier", "1");
            httpClient.Timeout = TimeSpan.FromMinutes(10);
            var buffer = File.ReadAllBytes(filePath);
            ByteArrayContent byteArray = new ByteArrayContent(buffer);
            byteArray.Headers.Add("ext", Path.GetExtension(filePath));
            var response = await httpClient.PostAsync("https://localhost:44335/api/FileV2/upload", byteArray);

            var result = await response.Content.ReadAsStringAsync();
            return result;
        }
    }
}
